package recursion;

import java.nio.CharBuffer;

/**
 * TOOD
 *输入：["H","a","n","n","a","h"]
 * 输出：["h","a","n","n","a","H"]
 * @author long
 * @date 2020-07-21 21:52
 */
public class reverseString {

   /* public static String  reverseString(String s) {
        int length=s.length();
        if (length<=1){
            return s;
        }
        String left=s.substring(0,length/2);
        String rigth=s.substring(length/2,length);
        String afterReverse=reverseString(rigth)+reverseString(left);
        return afterReverse;

    }
*/
   public static  String  reverseString(String  s){
       if (s==null||s.length()==0){
           return s;
       }
       char[] array=s.toCharArray();
       for (int left=0, right=s.length();left<right;left++,right--){
           swap(array,left,right);
       }
        return new String(array);
   }
   public static void  swap(char[] array,int left,int right){
       char temp=array[left];
       array[left] =array[right];
       array[right]=temp;
   }


   /*public static  void  reverseString(char[] s) {

      for (int i=0,j=s.length-1;i<j;i++,j--){
          char temp=s[i];
          s[i]=s[j];
          s[j]=temp;
      }

   }*/

    /*public void reverseString(char[] s) {

    }*/


    public static void main(String[] args) {
/*         String  s="ABCDEFG";
        final String s1 = reverseString(s);
        System.out.println( s1.toString());*/
        char[] str={'A','B','C','d'};
        /* char[] chars = reverseString(str);
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }*/
    }


}
